<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>MongoDB 安装 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>MongoDB 安装</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/MongoDB/">MongoDB</a>
			</span>
		
	</div>

	

	
		<h2 id="1-搭建-yum-源"><a href="#1-搭建-yum-源" class="headerlink" title="1. 搭建 yum 源"></a>1. 搭建 yum 源</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果安装epel扩展源，可以安装mongodb2.4版本，但这次我们要安装3.0版本，官方提供的源只支持64位系统</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /etc/yum.repos.d/mongodb-org-3.0.repo </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># vim /etc/yum.repos.d/mongodb-org-3.0.repo</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[mongodb-org-3.0]</div><div class="line">name=MongoDB Repository</div><div class="line">baseurl=http://repo.mongodb.org/yum/redhat/<span class="variable">$releasever</span>/mongodb-org/3.0/x86_64/ </div><div class="line">gpgcheck=0</div><div class="line">enabled=1</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/MongoDB%20%E5%AE%89%E8%A3%85/01.png?raw=true" alt=""></figure></p>
<h2 id="2-安装配置-MongoDB"><a href="#2-安装配置-MongoDB" class="headerlink" title="2. 安装配置 MongoDB"></a>2. 安装配置 MongoDB</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装很简单  yum install -y mongodb-org</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># yum install -y mongodb-org</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件 /etc/mongod.conf</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># vim /etc/mongod.conf</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">fork: <span class="literal">true</span></div><div class="line">pidFilePath: /var/run/mongodb/mongod.pid</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/MongoDB%20%E5%AE%89%E8%A3%85/02.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;把这两行后面#开头的注释删掉,否则重启的时候会有问题</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/MongoDB%20%E5%AE%89%E8%A3%85/03.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;要想绑定多个ip，在bind_ip 后写多个ip，中间用逗号分隔</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/MongoDB%20%E5%AE%89%E8%A3%85/04.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;监听全部ip留空即可</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/MongoDB%20%E5%AE%89%E8%A3%85/05.png?raw=true" alt=""></figure></p>
<h2 id="3-启动-MongoDB"><a href="#3-启动-MongoDB" class="headerlink" title="3. 启动 MongoDB"></a>3. 启动 MongoDB</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># /etc/init.d/mongod start</span></div><div class="line">Starting mongod: [确定]</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># echo never &gt; /sys/kernel/mm/transparent_hugepage/enabled</span></div><div class="line">[root@mongodb ~]<span class="comment"># echo never &gt; /sys/kernel/mm/transparent_hugepage/defrag</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /etc/security/limits.conf </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># vim /etc/security/limits.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">mongod soft nofile 64000</div><div class="line">mongod hard nofile 64000</div><div class="line">mongod soft nproc 32000</div><div class="line">mongod hard nproc 32000</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/MongoDB%20%E5%AE%89%E8%A3%85/06.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动：service mongod start</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@mongodb ~]<span class="comment"># service mongod restart</span></div><div class="line">Stopping mongod: [确定]</div><div class="line">Starting mongod: [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动的过程会比较慢，这是它在写数据 /var/lib/mongo</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/MongoDB/2. MongoDB 安装/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
